#include "GeomPrimitives.h"
#include <Windows.h>
#include <gl/GL.h>

namespace steam
{
	namespace moon
	{
		coal::IMesh* GeomPrimitives::createCube(float sideLength)
		{
			return GeomPrimitives::createBox(sideLength, sideLength, sideLength);
		}

		coal::IMesh* GeomPrimitives::createPlane(float sideLength, const base::Vector3& normalAxis)
		{
			return NULL;
		}

		coal::IMesh* GeomPrimitives::createBox(float width, float length, float height)
		{
			return NULL;
		}

		coal::IMesh* GeomPrimitives::createCylinder(float radius, float height, const base::Vector3& axis)
		{
			return NULL;
		}

		coal::IMesh* GeomPrimitives::createTube(float radius, float height, const base::Vector3& axis)
		{
			return NULL;
		}

		coal::IMesh* GeomPrimitives::createCircle(float radius, const base::Vector3& axis)
		{
			return NULL;
		}

		void GeomPrimitives::drawBox(float width, float height, float length)
		{
			glDisable(GL_TEXTURE_2D);
			glEnable(GL_COLOR_MATERIAL);
			glColor3f(1.f, 0.f, 0.f);
			
			glBegin(GL_QUADS);
			// Front Face
			glTexCoord2f(0.0f, 0.0f); glVertex3f(-1.0f * width/2.f, -1.0f * height/2.f,  1.0f * length/2.f);  // Bottom Left Of The Texture and Quad
			glTexCoord2f(1.0f, 0.0f); glVertex3f(1.0f * width/2.f, -1.0f * height/2.f,  1.0f * length/2.f);  // Bottom Right Of The Texture and Quad
			glTexCoord2f(1.0f, 1.0f); glVertex3f(1.0f * width/2.f,  1.0f * height/2.f,  1.0f * length/2.f);  // Top Right Of The Texture and Quad
			glTexCoord2f(0.0f, 1.0f); glVertex3f(-1.0f * width/2.f,  1.0f * height/2.f,  1.0f * length/2.f);  // Top Left Of The Texture and Quad
			glEnd();
			glBegin(GL_QUADS);
			// Back Face
			glTexCoord2f(1.0f, 0.0f); glVertex3f(-1.0f * width/2.f, -1.0f * height/2.f, -1.0f * length/2.f);  // Bottom Right Of The Texture and Quad
			glTexCoord2f(1.0f, 1.0f); glVertex3f(-1.0f * width/2.f,  1.0f * height/2.f, -1.0f * length/2.f);  // Top Right Of The Texture and Quad
			glTexCoord2f(0.0f, 1.0f); glVertex3f(1.0f * width/2.f,  1.0f * height/2.f, -1.0f * length/2.f);  // Top Left Of The Texture and Quad
			glTexCoord2f(0.0f, 0.0f); glVertex3f(1.0f * width/2.f, -1.0f * height/2.f, -1.0f * length/2.f);  // Bottom Left Of The Texture and Quad
			glEnd();
			glBegin(GL_QUADS);
			// Top Face
			glTexCoord2f(0.0f, 1.0f); glVertex3f(-1.0f * width/2.f,  1.0f * height/2.f, -1.0f * length/2.f);  // Top Left Of The Texture and Quad
			glTexCoord2f(0.0f, 0.0f); glVertex3f(-1.0f * width/2.f,  1.0f * height/2.f,  1.0f * length/2.f);  // Bottom Left Of The Texture and Quad
			glTexCoord2f(1.0f, 0.0f); glVertex3f(1.0f * width/2.f,  1.0f * height/2.f,  1.0f * length/2.f);  // Bottom Right Of The Texture and Quad
			glTexCoord2f(1.0f, 1.0f); glVertex3f(1.0f * width/2.f,  1.0f * height/2.f, -1.0f * length/2.f);  // Top Right Of The Texture and Quad
			glEnd();
			glBegin(GL_QUADS);
			// Bottom face
			glTexCoord2f(1.0f, 1.0f); glVertex3f(-1.0f * width/2.f, -1.0f * height/2.f, -1.0f * length/2.f);  // Top Right Of The Texture and Quad
			glTexCoord2f(0.0f, 1.0f); glVertex3f(1.0f * width/2.f, -1.0f * height/2.f, -1.0f * length/2.f);  // Top Left Of The Texture and Quad
			glTexCoord2f(0.0f, 0.0f); glVertex3f(1.0f * width/2.f, -1.0f * height/2.f,  1.0f * length/2.f);  // Bottom Left Of The Texture and Quad
			glTexCoord2f(1.0f, 0.0f); glVertex3f(-1.0f * width/2.f, -1.0f * height/2.f,  1.0f * length/2.f);  // Bottom Right Of The Texture and Quad
			glEnd();
			glBegin(GL_QUADS);		
			// Right face
			glTexCoord2f(1.0f, 0.0f); glVertex3f(1.0f * width/2.f, -1.0f * height/2.f, -1.0f * length/2.f);  // Bottom Right Of The Texture and Quad
			glTexCoord2f(1.0f, 1.0f); glVertex3f(1.0f * width/2.f,  1.0f * height/2.f, -1.0f * length/2.f);  // Top Right Of The Texture and Quad
			glTexCoord2f(0.0f, 1.0f); glVertex3f(1.0f * width/2.f,  1.0f * height/2.f,  1.0f * length/2.f);  // Top Left Of The Texture and Quad
			glTexCoord2f(0.0f, 0.0f); glVertex3f(1.0f * width/2.f, -1.0f * height/2.f,  1.0f * length/2.f);  // Bottom Left Of The Texture and Quad
			glEnd();
			glBegin(GL_QUADS);
			// Left Face
			glTexCoord2f(0.0f, 0.0f); glVertex3f(-1.0f * width/2.f, -1.0f * height/2.f, -1.0f * length/2.f);  // Bottom Left Of The Texture and Quad
			glTexCoord2f(1.0f, 0.0f); glVertex3f(-1.0f * width/2.f, -1.0f * height/2.f,  1.0f * length/2.f);  // Bottom Right Of The Texture and Quad
			glTexCoord2f(1.0f, 1.0f); glVertex3f(-1.0f * width/2.f,  1.0f * height/2.f,  1.0f * length/2.f);  // Top Right Of The Texture and Quad
			glTexCoord2f(0.0f, 1.0f); glVertex3f(-1.0f * width/2.f,  1.0f * height/2.f, -1.0f * length/2.f);  // Top Left Of The Texture and Quad
			glEnd();
			
			glColor3f(1.f, 1.f, 1.f);
			glDisable(GL_COLOR_MATERIAL);
			glEnable(GL_TEXTURE_2D);
		}

		void GeomPrimitives::drawBox( const base::Vector3& size )
		{
			GeomPrimitives::drawBox(size.x, size.y, size.z);
		}

	}
}